home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / addcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.1 KB  |  45 lines

  1. /*
  2. \funcref{addcmd}{char $**$addcmd (\params)}
  3.     {
  4.         {char} {**cmd} {{\em argv}-like array of strings}
  5.         {char} {*string} {string to add to {\em cmd}}
  6.     }
  7.     {resized {\em cmd} to which reference to {\em string} is added}
  8.     {xrealloc()}
  9.     {}
  10.     {addcmd.c}
  11.     {
  12.  
  13.         Function {\em addcmd()} expects a pointer to an array of {\em char $*$}'s as
  14.         first argument. This pointer may be {\em NULL}. The {\em argv}-like
  15.         array is expanded to hold a reference to {\em string}.
  16.  
  17.         The reallocated array {\em cmd} is returned. The last field in the
  18.         array is {\em NULL} to indicate the ending of the list.
  19.  
  20.         {\bf Note that} a reference to {\em string} itself is not added to the
  21.         list: a duplicate is made.
  22.  
  23.     }
  24. */
  25.  
  26. #include "icm-exec.h"
  27.  
  28. char **addcmd (cmd, string)
  29. char **cmd, *string;
  30. {
  31.     register int
  32.         i,
  33.         size = 0;
  34.  
  35.     if (cmd)
  36.         for (i = 0; cmd [i]; i++)
  37.             size++;
  38.  
  39.     cmd = xrealloc (cmd, (size + 2) * sizeof (char *));
  40.     cmd [size] = xstrdup (string);
  41.     cmd [size + 1] = NULL;
  42.  
  43.     return (cmd);
  44. }
  45.